package com.example.Nurse_Notifier;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ExpandableListView;
import interfaces.ChangeState;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

public class StatsFragment extends Fragment implements ChangeState {

    private StatsContainer statsContainer;
    private ArrayList<StatsItem> statsList;
    private Activity activity;
    XbeeDeviceContainer xbeeDeviceContainer;
    List<String> defaultList = Arrays.asList("За сегодня :", "За неделю :", "За месяц :", "За все время :");
    HashMap<String, String> hashMap = new HashMap<String, String>();

    public StatsFragment(XbeeDeviceContainer xbeeDeviceContainer, FragmentActivity activity) {
        this.xbeeDeviceContainer = xbeeDeviceContainer;
        this.activity = activity;
        statsList = new ArrayList<StatsItem>();
        LoadStats();
        statsContainer = new StatsContainer(activity.getApplicationContext(), statsList);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.statslayot, container, false);
        ExpandableListView expandableListView = (ExpandableListView) rootView.findViewById(R.id.expandableListView);
        expandableListView.setAdapter(statsContainer);
        return rootView;
    }

    public void LoadStats() {
//        hashMap.put("day", "За сегодня");
//        hashMap.put("week", "За неделю");
//        hashMap.put("month", "За месяц");
//        hashMap.put("overall", "За все время");

        //Минимальное время
        ArrayList<String> minTime = new ArrayList<String>(defaultList);
        statsList.add(new StatsItem("Минимальное время", minTime));
        //Среднее время
        ArrayList<String> maxTime = new ArrayList<String>(defaultList);
        statsList.add(new StatsItem("Максимальное время", maxTime));
        //Максимальное время
        ArrayList<String> averTime = new ArrayList<String>(defaultList);
        statsList.add(new StatsItem("Среднее время", averTime));

        ArrayList<String> dropCnt = new ArrayList<String>(defaultList);
        statsList.add(new StatsItem("Количество капельниц", dropCnt));

        statsList.add(new StatsItem("Статистика по капельницам", new ArrayList<String>()));
    }

    public void setTime(final int listItem, final int indexItem, final String time) {
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                statsList.get(listItem).setItemParameter(indexItem, time);
            }
        });
    }

    @Override
    public void addObject(XbeeDevice object) {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public void removeObject(int indx) {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public void changeObjectStatus(int objectId, int status) {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    public void clearStats() {

    }
}
